<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<html>
	<script type="text/javascript">
	function executeTest(path)
	{	
	    var fileName = document.getElementById("path").value;
		if(fileName!=0 && fileName.length > 0){
			//document.executeForm.submit();["resultFrame"].location.href(path + "/executeVIRest.html?path="+fileName);
			document.executeForm.submit();
		} 
		else 
		{
		 	// alert("请选择要导入的文件！");
		 	return;
		}
    }

	function searchInterface(path)
	{
		var interfaceName = document.getElementById("interfaceName").value;
		var resultType = document.getElementById("resultType").value;
		if(interfaceName != "" || resultType != "")
		{
			var url = path + "/searchInterface.html?";
			if (interfaceName != "")
			{
				url = url + "interfaceName=" + interfaceName;
			}
			if (resultType != "")
			{
				if (interfaceName != "")
				{
					url = url + "&";
				}
				url = url + "resultType=" + resultType;
			}
			location.href = url;
		} 
		else 
		{
		 	alert("请选择搜索的接口名称或者结果类型！");
		 	return;
		}
	}

	function browseFolder(path) {
		 try {
			 if (window.ActiveXObject)
			 {
				 var Message = "\u8bf7\u9009\u62e9\u6587\u4ef6\u5939"; //选择框提示信息
				 var Shell = new ActiveXObject("Shell.Application");
				 var Folder = Shell.BrowseForFolder(0, Message, 64, 17); //起始目录为：我的电脑
				 //var Folder = Shell.BrowseForFolder(0,Message,0); //起始目录为：桌面
				 if (Folder != null) {
					 Folder = Folder.items(); // 返回 FolderItems 对象
					 Folder = Folder.item(); // 返回 Folderitem 对象
					 Folder = Folder.Path; // 返回路径
					 if (Folder.charAt(Folder.length - 1) != "") {
					 	Folder = Folder + "";
					 }
					 document.getElementById(path).value = Folder;
					 return Folder;
				 }
			 }
			 else
			 {
				alert("抱歉，文件夹选择器当前只支持IE内核的浏览器。\n\n若您一定要使用其他浏览器：\n\t1.更新config.properties配置文件里的根目录，并重启服务器；\n\t2.将路径贴入文本框中。");
			 }
		 }
		 catch (e) {
		 	alert(e.message+"，需要对ActiveX 控件初始化并执行脚本设置为启用状态。\n\n操作步骤：IE浏览器 -> 工具 -> Internet选项 -> 安全 -> 可信站点 -> 自定义级别 -> ActiveX控件和插件 -> 对未标记为可安全执行脚本的 ActiveX 控件初始化并执行脚本");
		 }
	}
    </script>
	<head>
		<title>VIRest自动化测试系统</title>
		<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
		<style type="text/css">
body {
	font-family: Tahoma, Verdana;
	font-size: 12px
}

table {
	font-family: Tahoma, Verdana;
	color: #111111;
	font-size: 12px border :     0;
	margin: 0;
	padding: 0;
	border: 0px solid #ccc;
	border-collapse: collapse;
	font-size: 12px;
}

td {
	LINE-HEIGHT: 180%
}
</style>
	</head>

	<body>
		<table width="99%" border="0" align="center"
			style="position: absolute;" cellpadding="0 " cellspacing="1 ">
			<tr>
				<td align="right" width="60%" style="font-weight: bold; font-size: x-large;color: #3300CC">
						VIRest自动化测试工具
				</td>
				<td width="40%" align="right">
					<a href="<%=request.getContextPath()%>/help.jsp" target="_black"><img src="<%=request.getContextPath()%>/resources/attachment/images/question.jpg" title="如果不选择脚本路径则为系统默认脚本！" align="right" width="20px" height="20px"/>帮助中心</a>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<form action="executeVIRest.html" method="get" name="executeForm">
						<center>
							<table width="100%" height="100%">
								<tr>
									<td align="left">
										<input id="path" type="text" name="path" value="${filePath }"
											size="28" style="width: 70%;">
										&nbsp;&nbsp;
										<input type="button" id="chooser" value="选择脚本路径"
											onclick="browseFolder('path');" style="width: 10%">
										&nbsp;&nbsp;
										<input type="submit" id="execute" value="执行自动化测试" style="width: 15%"/>
									</td>
								</tr>
							</table>
						</center>
					</form>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<table width="100%" border="1" align="center"
						style="position: absolute;" cellpadding="0 " cellspacing="1 ">
						<tr>
							<td colspan="6" nowrap align="left">
								<table width="100%">
									<tr>
										<td align="center" width="50%" style="font-weight: bold;">
											总数：<font color="red">${total_count-0}</font>&nbsp;&nbsp;&nbsp;
											成功数：<font color="red">${success_count-0}</font>&nbsp;&nbsp;&nbsp;
											失败数：<font color="red">${total_count-success_count}</font>&nbsp;&nbsp;&nbsp;
											${expendTime}
										</td>
										<td align="right" width="50%">
											<input type="text" name="interfaceName" id="interfaceName" size="28"/>&nbsp;&nbsp;
											<select name="resultType" id="resultType">
												<option value="">选择结果类型</option>
												<option value="false">失败</option>
												<option value="true">成功</option>
											</select>&nbsp;&nbsp;
											<input type="button" name="search" id="search" value="搜索接口" onclick="searchInterface('<%=request.getContextPath()%>');"/>
										</td>
									</tr>
								</table>
							</td>
						</tr>
						<tr bgcolor="#d7e5f6">
							<td nowrap align="center" width="50px" style="font-weight:bold; ">
								序列号
							</td>
							<td nowrap align="center" align="center" style="font-weight:bold; ">
								接口名
							</td>
							<td align="center" align="center" style="font-weight:bold; "> 
								脚本路径
							</td>
							<td align="center" align="center" style="font-weight:bold; ">
								响应消息
							</td>
							<td align="center" width="30px" align="center" style="font-weight:bold; ">
								比对结果
							</td>
							<td align="center" width="60px" style="font-weight:bold; " >
								期望结果比较
							</td>
						</tr>

						<c:if test="${ empty resultMap}">
							<tr>
								<td colspan="6">
									<div align="center">
										<strong>无记录</strong>
									</div>
								</td>
							</tr>
						</c:if>
						<c:if test="${!empty resultMap}">
							<c:forEach items="${resultMap}" var="respResult"
								varStatus="loopStatus">
								<c:set var="matchedResult" value="${respResult.value}"></c:set>
								<c:choose>
									<c:when test="${matchedResult.flag }">
										<tr>
									</c:when>
									<c:otherwise>
										<tr style="color: red;">
									</c:otherwise>
								</c:choose>
									<td nowrap align="center">
										${loopStatus.index+1}
									</td>
									<td nowrap align="left" style="padding-left: 2px;padding-right: 2px;">
										<strong><c:out value="${respResult.key}" /></strong>
									</td>
									<td align="left" style="padding-left: 2px;padding-right: 2px;">
										${matchedResult.scriptPath }
									</td>
									<td align="center" style="padding-left: 2px;padding-right: 2px;">
										<strong>${matchedResult.msg }</strong>
									</td>
									<td align="center">
										${matchedResult.flag }
									</td>
									<td align="center">
										<a
											href="<%=request.getContextPath()%>/compareResult.html?resultKey=${respResult.key }"
											target="_blank">查看脚本</a>
									</td>
								</tr>
							</c:forEach>
						</c:if>
					</table>
				</td>
			</tr>
		</table>
	</body>
</html>
